home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
print
/
gsview10.zip
/
print.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-29
|
24KB
|
824 lines
/*
* print.c -- Printing operations for GSVIEW.EXE,
* a graphical interface for MS-Windows Ghostscript
* Copyright (C) 1993 Russell Lang
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: Russell Lang
* Internet: rjl@monu1.cc.monash.edu.au
*/
#define STRICT
#include <windows.h>
#include <windowsx.h>
#include <commdlg.h>
#include <shellapi.h>
#include <mmsystem.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <dir.h>
#include <io.h>
#define NeedFunctionPrototypes 1
#include "ps.h"
#include "gsview.h"
static char pcfname[MAXSTR]; /* name of temporary command file for printing */
static char pfname[MAXSTR]; /* name of temporary file for printing options */
int gp_printfile(char *filename, char *port);
/* documented in Device Driver Adaptation Guide */
/* Prototypes taken from print.h */
DECLARE_HANDLE(HPJOB);
HPJOB WINAPI OpenJob(LPSTR, LPSTR, HPJOB);
int WINAPI StartSpoolPage(HPJOB);
int WINAPI EndSpoolPage(HPJOB);
int WINAPI WriteSpool(HPJOB, LPSTR, int);
int WINAPI CloseJob(HPJOB);
int WINAPI DeleteJob(HPJOB, int);
int WINAPI WriteDialog(HPJOB, LPSTR, int);
int WINAPI DeleteSpoolPage(HPJOB);
struct prop_item_s {
char name[MAXSTR];
char value[MAXSTR];
};
char not_defined[] = "[Not defined]";
struct prop_item_s *
get_properties(char *device)
{
char *entries, *p;
int i, numentry;
struct prop_item_s *proplist;
entries = malloc(PROFILE_SIZE);
if (entries == (char *)NULL)
return NULL;
GetPrivateProfileString(device, NULL, "", entries, PROFILE_SIZE, INIFILE);
if (strlen(entries) == 0) {
free(entries);
return NULL;
}
p = entries;
for (numentry=0; p!=(char *)NULL && strlen(p)!=0; numentry++)
p += strlen(p) + 1;
proplist = (struct prop_item_s *)malloc((numentry+1) * sizeof(struct prop_item_s));
if (proplist == (struct prop_item_s *)NULL) {
free(entries);
return NULL;
}
p = entries;
for (i=0; i<numentry; i++) {
strcpy(proplist[i].name, p);
GetPrivateProfileString(device, p, "", proplist[i].value, sizeof(proplist->value), INIFILE);
p += strlen(p) + 1;
}
proplist[numentry].name[0] = '\0';
proplist[numentry].value[0] = '\0';
free(entries);
return proplist;
}
/* dialog box for selecting printer properties */
BOOL CALLBACK _export
PropDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
{
char buf[128];
int iprop;
int ivalue;
WORD notify_message;
char *p;
char *value;
static char device[MAXSTR]; /* contains printer device name */
static struct prop_item_s* propitem;
char section[MAXSTR];
switch (wmsg) {
case WM_INITDIALOG:
lstrcpy(device, (LPSTR)lParam); /* initialise device name */
propitem = get_properties(device);
if (propitem == (struct prop_item_s *)NULL) {
EndDialog(hDlg, FALSE);
return TRUE;
}
for (iprop=0; propitem[iprop].name[0]; iprop++) {
SendDlgItemMessage(hDlg, PROP_NAME, CB_ADDSTRING, 0,
(LPARAM)((LPSTR)propitem[iprop].name+1));
}
SendDlgItemMessage(hDlg, PROP_NAME, CB_SETCURSEL, 0, 0L);
/* force update of PROP_VALUE */
SendDlgNotification(hDlg, PROP_NAME, CBN_SELCHANGE);
return TRUE;
case WM_COMMAND:
notify_message = GetNotification(wParam,lParam);
switch (LOWORD(wParam)) {
case ID_HELP:
SendMessage(hwndimg, help_message, 0, 0L);
return(FALSE);
case PROP_NAME:
if (notify_message != CBN_SELCHANGE) {
return FALSE;
}
iprop = (int)SendDlgItemMessage(hDlg, PROP_NAME, CB_GETCURSEL, 0, 0L);
if (iprop == CB_ERR) {
return FALSE;
}
/* now look up entry in gsview.ini */
/* and update PROP_VALUE list box */
strcpy(section, device);
strcat(section, " values");
GetPrivateProfileString(section, propitem[iprop].name, "", buf, sizeof(buf)-2, INIFILE);
buf[strlen(buf)+1] = '\0'; /* put double NULL at end */
SendDlgItemMessage(hDlg, PROP_VALUE, CB_RESETCONTENT, 0, 0L);
SendDlgItemMessage(hDlg, PROP_VALUE, CB_ADDSTRING, 0,
(LPARAM)((LPSTR)not_defined));
p = buf;
if (*p != '\0') {
EnableWindow(GetDlgItem(hDlg, PROP_VALUE), TRUE);
while (*p!='\0') {
value = p;
while ((*p!='\0') && (*p!=','))
p++;
*p++ = '\0';
SendDlgItemMessage(hDlg, PROP_VALUE, CB_ADDSTRING, 0,
(LPARAM)((LPSTR)value));
}
}
SendDlgItemMessage(hDlg, PROP_VALUE, CB_SELECTSTRING, -1, (LPARAM)(LPSTR)propitem[iprop].value);
SetDlgItemText(hDlg, PROP_VALUE, propitem[iprop].value);
return FALSE;
case PROP_VALUE:
if (notify_message == CBN_SELCHANGE) {
iprop = (int)SendDlgItemMessage(hDlg, PROP_NAME, CB_GETCURSEL, 0, 0L);
if (iprop == CB_ERR)
return FALSE;
ivalue = (int)SendDlgItemMessage(hDlg, PROP_VALUE, CB_GETCURSEL, 0, 0L);
if (ivalue == CB_ERR)
return FALSE;
SendDlgItemMessage(hDlg, PROP_VALUE, CB_GETLBTEXT, ivalue, (LPARAM)(LPSTR)propitem[iprop].value);
}
if (notify_message == CBN_EDITCHANGE) {
iprop = (int)SendDlgItemMessage(hDlg, PROP_NAME, CB_GETCURSEL, 0, 0L);
if (iprop == CB_ERR)
return FALSE;
GetDlgItemText(hDlg, PROP_VALUE, (LPSTR)propitem[iprop].value, sizeof(propitem->value));
}
return FALSE;
case IDOK:
for (iprop=0; propitem[iprop].name[0]; iprop++) {
WritePrivateProfileString(device, propitem[iprop].name, propitem[iprop].value, INIFILE);
}
free((char *)propitem);
EndDialog(hDlg, TRUE);
return TRUE;
case IDCANCEL:
free((char *)propitem);
EndDialog(hDlg, FALSE);
return TRUE;
}
break;
}
return FALSE;
}
/* dialog box for selecting printer device and resolution */
BOOL CALLBACK _export
DeviceDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
{
char buf[128];
int idevice;
WORD notify_message;
char *p;
char *res;
int numentry;
char entry[MAXSTR];
struct prop_item_s *proplist;
switch (wmsg) {
case WM_INITDIALOG:
p = get_devices();
res = p; /* save for free() */
for (numentry=0; p!=(char *)NULL && strlen(p)!=0; numentry++) {
SendDlgItemMessage(hDlg, DEVICE_NAME, CB_ADDSTRING, 0,
(LPARAM)((LPSTR)p));
p += strlen(p) + 1;
}
free(res);
if (SendDlgItemMessage(hDlg, DEVICE_NAME, CB_SELECTSTRING, 0, (LPARAM)(LPSTR)device_name)
== CB_ERR)
SendDlgItemMessage(hDlg, DEVICE_NAME, CB_SETCURSEL, 0, 0L);
/* force update of DEVICE_RES */
SendDlgNotification(hDlg, DEVICE_NAME, CBN_SELCHANGE);
if (SendDlgItemMessage(hDlg, DEVICE_RES, CB_SELECTSTRING, 0, (LPARAM)(LPSTR)device_resolution)
== CB_ERR)
SendDlgItemMessage(hDlg, DEVICE_RES, CB_SETCURSEL, 0, 0L);
return TRUE;
case WM_COMMAND:
notify_message = GetNotification(wParam,lParam);
switch (LOWORD(wParam)) {
case ID_HELP:
SendMessage(hwndimg, help_message, 0, 0L);
return(FALSE);
case DEVICE_NAME:
if (notify_message != CBN_SELCHANGE) {
return FALSE;
}
idevice = (int)SendDlgItemMessage(hDlg, DEVICE_NAME, CB_GETCURSEL, 0, 0L);
if (idevice == CB_ERR) {
return FALSE;
}
SendDlgItemMessage(hDlg, DEVICE_NAME, CB_GETLBTEXT, idevice, (LPARAM)(LPSTR)entry);
if ( (proplist = get_properties(entry)) != (struct prop_item_s *)NULL ) {
f